package com.test.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.test.classs.*;
import com.test.connection_hive.hive_SQL;
import com.test.page.PageInfo;

public class deal_dh_professional {
	/**
	 * @author qinzhen
	 * @time 2015/3/15
	 * @param stmt
	 * @param pageInfo
	 * @param fieldName
	 * @param value
	 * @return
	 * @throws SQLException
	 * @throws Exception
	 * @function 根据字段名称和值，查询专业信息    ,  如专业id
	 */
	public static List<dh_professional> selectDh_professionalFromFieldName(Statement stmt,PageInfo pageInfo,
			String fieldName, String value) throws SQLException, Exception {

		String querySQL = "select * from studentmanagesystem.dh_professional where "
				+ fieldName + "='" + value + "\'";
		
//		if (pageInfo != null) {
//			querySQL += ("where cid>=" + pageInfo.getCurrentPageNow()
//					+ " and cid<= " + pageInfo.getPageSize());
//			pageInfo.setTotalResult(getCount("id", "dh_grade"));
//
//		}
		List<dh_professional> professionalList = new ArrayList<dh_professional>();
		ResultSet res = stmt.executeQuery(querySQL);

		while (res.next()) {
			dh_professional professional = new dh_professional();

			professional.setCid(res.getString("cid"));
			professional.setAddTime(res.getString("addtime"));
			professional.setId(res.getString("id"));
			professional.setIsDelete(res.getString("isdelete"));
			professional.setName(res.getString("name"));
			professionalList.add(professional);
		}
		return professionalList;
	}

	/**
	 * @author qinzhe
	 * @time 2015/3/15
	 * @param stmt
	 * @param pageInfo
	 * @return List<dh_professional>
	 * @throws SQLException
	 * @throws Exception
	 * @function 分页查询所有专业信息
	 */
	public static List<dh_professional> selectAllDh_professional(Statement stmt,
			PageInfo pageInfo) throws SQLException, Exception {
//		System.out.println("pageInfo.getCurrentPageNow()="
//				+ pageInfo.getCurrentPageNow() + " "
//				+ "pageInfo.getPageSize()=" + pageInfo.getPageSize());
		// querySQL="select * from studentmanagesystem.hd_student where name='"+loginname+"\'";
		String querySQL = "select * from studentmanagesystem.dh_professional ";
		if (pageInfo != null) {
			querySQL += ("where cid>=" + pageInfo.getCurrentPageNow()
					+ " and cid<= " + pageInfo.getPageSize());
			pageInfo.setTotalResult(hive_SQL.getCount("id", "dh_professional"));

		}
		List<dh_professional> professionalList = new ArrayList<dh_professional>();
		ResultSet res = stmt.executeQuery(querySQL);

		while (res.next()) {
			dh_professional professional = new dh_professional();

			professional.setCid(res.getString("cid"));
			professional.setAddTime(res.getString("addtime"));
			professional.setId(res.getString("id"));
			professional.setIsDelete(res.getString("isdelete"));
			professional.setName(res.getString("name"));
			professionalList.add(professional);
		}
		return professionalList;
	}
}
